<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-item label="耳标号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['earMark', validatorRules.earMark]"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="牧场名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['pastureName']" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="牛舍名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['cowshedName']"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['sex']" :trigger-change="true" dictCode="cattle_sex"  />
            </a-form-item>
          </a-col>

<!--          基础信息-->
          <a-col :span="12">
            <a-form-item label="品种" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['variety']" :trigger-change="true" dictCode="cattle_variety"  />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="花色" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['color']" :trigger-change="true" dictCode="cattle_color"  />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="养殖种类" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['culturedSpecies']" :trigger-change="true" dictCode="cattle_species"  />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="生长状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['growthStatus']" :trigger-change="true" dictCode="cattle_growth_status"  />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="繁殖状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['breedStatus']" :trigger-change="true" dictCode="cattle_breed_status"  />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="当前胎次" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['currentParity']" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date  v-decorator="['birthDate']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
<!--          <a-col :span="12">-->
<!--            <a-form-item label="月龄" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input-number v-decorator="['monthAge']"  style="width: 100%" />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :span="12">
            <a-form-item label="出生体重" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['birthWeight']"  style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="实时体重" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['weight']"  style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="来源耳号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fromEarMark']"   ></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :span="12">-->
<!--            <a-form-item label="旧耳号" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input v-decorator="['oldEarMark']"  ></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage';
  import pick from 'lodash.pick';
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CattleArchivesForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          earMark: {
            rules: [
              { required: true, message: '请输入耳标号!'},
            ]
          },
        },
        url: {
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'earMark','pastureName','cowshedName','color','sex','birthDate','currentParity','variety','culturedSpecies',
            'breedStatus','growthStatus','fromEarMark','birthWeight','weight','createBy','createTime','updateBy','updateTime'))
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'earMark','pastureName','cowshedName','sex','birthDate','currentParity','variety','culturedSpecies',
          'breedStatus','growthStatus','fromEarMark','birthWeight','weight','createBy','createTime','updateBy','updateTime'))
      },
    }
  }
</script>